package com.tensquare.friend.service;
/*
 *ClassName:UserService
 *Description:
 *@author:可爱的大鸭子
 */

import com.netflix.discovery.converters.Auto;
import com.tensquare.friend.client.GatheringClient;
import com.tensquare.friend.client.LabelClient;
import com.tensquare.friend.dao.UserDao;
import com.tensquare.friend.pojo.Gath;
import com.tensquare.friend.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private FriendService friendService;
    @Autowired
    private LabelClient labelClient;
    @Autowired
    private GatheringClient gatheringClient;

    //未登录的时候查询全部列表
    public List<User> findAll() {
        return userDao.findAllByGatheringIsNotNullOrderByCreatetimeDesc();
    }

    //最新的三个
    public List<User> findTop3() {
        return userDao.findTop3ByTimeDesc();
    }

    public User findById(String id){
        return userDao.findById(id).get();
    }

    //查询我的推荐异性列表
    public List<User> getCommend(String id, int sex,int page,int size) {
        PageRequest pageRequest =  PageRequest.of(page-1, size);
        List<User> users=userDao.getCommend(id,sex);    //pageRequest
        for(User u:users){
            Double suit=friendService.getSuitability(id,u.getId());
            u.setSuit(suit);
            List<Integer> my_labels=(List)labelClient.getMyLabels(id).getData();
            List<Integer> other_labels=(List)labelClient.getMyLabels(u.getId()).getData();
            List<String> labels=friendService.getCommenList(my_labels,other_labels);
            u.setLabels(labels);

            List<Integer> my_gatherings=(List)gatheringClient.getMyGatherings(id).getData();
            List<Integer> other_gatherings=(List)gatheringClient.getMyGatherings(u.getId()).getData();
            List<String> gatherings = friendService.getCommenList(my_gatherings, other_gatherings);
            u.setGatherings(gatherings);
        }
        return users;
    }

    public List<Gath> getHotGatherings() {
        return userDao.getHotGatherings();
    }
}
